import pandas as pd
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
import time

driver = webdriver.Chrome(service=Service('D:\\myproject\\feng-huang\\1.自动化\\1.selenium\\chromedriver.exe'))
driver.maximize_window()
driver.get('https://www.foodtalks.cn/company/Yili/')
time.sleep(2)
dict_data = {
# '公司名称': '',
#     '公司简称': '',
#     '公司英文名称': '',
#     '公司英文简称': '',
#     '公司类型': '',
#     '成立时间': '',
#     '股票代码': '',
#     '公司总机': '',
#
#     '公司简介': '',
}
# 首页
driver.find_element(By.CLASS_NAME, 'tab-item').click()
time.sleep(2)
# 基本详情
# 公司名称
company1 = driver.find_element(By.XPATH, '//*[@id="app"]/div[2]/section/main/section/main/div[1]/div[1]/div[4]/div/div[2]/div[1]/div[2]/ul/li[1]/div[1]').text
try:
    company_full_name = driver.find_element(By.XPATH,
                                            '//*[@id="app"]/div[2]/section/main/section/main/div[1]/div[1]/div[4]/div/div[2]/div[1]/div[2]/ul/li[1]/div[2]/span').text

except:
    company_full_name = ''
dict_data['公司名称'] = company_full_name
# 简称
try:
    company_short_name = driver.find_element(By.XPATH,
                                             '//*[@id="app"]/div[2]/section/main/section/main/div[1]/div[1]/div[4]/div/div[2]/div[1]/div[2]/ul/li[2]/div[2]/span').text
except:
    company_short_name = ''
dict_data['公司简称'] = company_short_name
# 公司英文名称
try:
    company_english_name = driver.find_element(By.XPATH,
                                               '//*[@id="app"]/div[2]/section/main/section/main/div[1]/div[1]/div[4]/div/div[2]/div[1]/div[2]/ul/li[3]/div[2]/span').text
except:
    company_english_name = ''
dict_data['公司英文名称'] = company_english_name
# 公司英文简称
try:
    company_english_name_short = driver.find_element(By.XPATH,
                                                     '//*[@id="app"]/div[2]/section/main/section/main/div[1]/div[1]/div[4]/div/div[2]/div[1]/div[2]/ul/li[4]/div[2]/span').text
except:
    company_english_name_short = ''
dict_data['公司英文简称'] = company_english_name_short
# 公司类型
try:
    company_type = driver.find_element(By.XPATH,
                                       '//*[@id="app"]/div[2]/section/main/section/main/div[1]/div[1]/div[4]/div/div[2]/div[1]/div[2]/ul/li[5]/div[2]/a').text
except:
    company_type = ''
dict_data['公司类型'] = company_type
# 成立时间
try:
    company_establish_time = driver.find_element(By.XPATH,
                                                 '//*[@id="app"]/div[2]/section/main/section/main/div[1]/div[1]/div[4]/div/div[2]/div[1]/div[2]/ul/li[6]/div[2]/a').text
except:
    company_establish_time = ''
dict_data['成立时间'] = company_establish_time
# 股票代码
try:
    ticker_symbol = driver.find_element(By.XPATH,
                                        '//*[@id="app"]/div[2]/section/main/section/main/div[1]/div[1]/div[4]/div/div[2]/div[1]/div[2]/ul/li[7]/div[2]/span').text
except:
    ticker_symbol = ''
dict_data['股票代码'] = ticker_symbol
# 公司总机
try:
    company_phone = driver.find_element(By.XPATH,
                                        '//*[@id="app"]/div[2]/section/main/section/main/div[1]/div[1]/div[4]/div/div[2]/div[1]/div[2]/ul/li[8]/div[2]/span').text
except:
    company_phone = ''
dict_data['公司总机'] = company_phone
# 公司性质
try:
    company_property=driver.find_element(By.XPATH,'//*[@id="app"]/div[2]/section/main/section/main/div[1]/div[1]/div[4]/div/div[2]/div[1]/div[2]/ul/li[9]/div[2]/a/span').text
except:
    company_property=''
dict_data['公司性质']=company_property
# 行业分类
try:
    industry_classification=driver.find_element(By.XPATH,'//*[@id="app"]/div[2]/section/main/section/main/div[1]/div[1]/div[4]/div/div[2]/div[1]/div[2]/ul/li[11]/div[2]').text
except:
    industry_classification=''
dict_data['行业分类']=industry_classification

# 主要品牌
try:
    Major_brands=driver.find_element(By.XPATH,'//*[@id="app"]/div[2]/section/main/section/main/div[1]/div[1]/div[4]/div/div[2]/div[1]/div[2]/ul/li[12]/div[2]').text
except:
    Major_brands=''
dict_data['主要品牌']=Major_brands
# 主要产品
try:
    Major_products = driver.find_element(By.XPATH,'//*[@id="app"]/div[2]/section/main/section/main/div[1]/div[1]/div[4]/div/div[2]/div[1]/div[2]/ul/li[13]/div[2]').text
except:
    Major_products = ''
dict_data['主要产品'] = Major_products
# 公司总部
try:
    company_headquarters = driver.find_element(By.XPATH,'//*[@id="app"]/div[2]/section/main/section/main/div[1]/div[1]/div[4]/div/div[2]/div[1]/div[2]/ul/li[15]/div[2]/span').text
except:
    company_headquarters = ''
dict_data['公司总部'] = company_headquarters

# 公司官网
try:
    company_website = driver.find_element(By.XPATH,'//*[@id="app"]/div[2]/section/main/section/main/div[1]/div[1]/div[4]/div/div[2]/div[1]/div[2]/ul/li[14]/div[2]/a').text
except:
    company_website = ''
dict_data['公司官网'] = company_website
# 简介
try:
    driver.find_element(By.XPATH,
                        '/html/body/div[1]/div[2]/section/main/section/main/div[1]/div[1]/div[4]/div/div[1]/div[1]/div[2]/div[3]/span').click()
    content = driver.find_element(By.CLASS_NAME, 'content').text
except:
    content = ''
dict_data['公司简介'] = content
print(dict_data)
